<template>
  <div class="recommend">
    <!-- //使用list列表组件 -->
    <van-list
      v-model:loading="state.loading"
      :finished="state.finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <ul>
        <!-- //渲染数据 -->
        <li class="recommend-frame" v-for="item in state.list" :key="item.id">
          <router-link :to="'/details/' + item.id">
            <div class="recommend-map">
              <img :src="item.Imgurl" alt="" />
            </div>
            <div class="recommend-details">
              <div class="recommend-title">
                <div class="recommend-title-left">
                  <h3>{{ item.title }}</h3>
                </div>
                <div class="recommend-title-right">
                  <span class="recommend-star">
                    <img :src="require('@/assets/images/xing.png')" alt="" />
                  </span>
                  <span class="recommend-grade">{{ item.score }}</span>
                </div>
              </div>
              <div class="recommend-content">
                {{ item.synopsis }}
              </div>
            </div>
          </router-link>
        </li>
      </ul>
    </van-list>
  </div>
</template>

<script>
//引入插件
import { reactive } from "vue";
import { getmoreApi } from "@/utils/api.js";

export default {
  //保存数据
  setup() {
    const state = reactive({
      list: [],
      loading: false,
      finished: false,
    });
    //设置页面下拉加载更多
    let pageSize = 2;
    let currentPage = 1;
    const onLoad = async () => {
      const res = await getmoreApi({
        pageSize,
        currentPage,
      });
      state.list.push(...res.result);
      currentPage++;

      state.loading = false;

      if (state.list.length >= res.count) {
        state.finished = true;
      }
    };
    //导出数据
    return {
      state,
      onLoad,
    };
  },
};
</script>

<style scoped>
.recommend {
  position: fixed;
  left: 0;
  right: 0;
  z-index: -1;
  top: 60px;
  bottom: 57px;
  overflow-y: scroll;
  background: white;
}
.recommend-frame {
  width: 343px;
  height: 266px;
  margin: 20px 16px 0;
  background: white;
}
.recommend-map {
  width: 343px;
  height: 192px;
}
.recommend-map img {
  width: 100%;
  height: 100%;
}
.recommend-details {
  width: 343px;
  height: 74px;
}
.recommend-title {
  width: 100%;
  height: 18px;
  margin-top: 16px;

  display: flex;
  justify-content: space-between;
}
.recommend-title-left {
  margin-left: 14px;
  font-size: 18px;
  font-weight: 900;
  color: #333333;
}
.recommend-title-right {
  font-size: 21px;
  line-height: 18px;
  margin-right: 14px;
  color: #32b9ba;
}
.recommend-star img {
  width: 18px;
  height: 16px;
  margin-right: 5px;
}
.recommend-content {
  margin-left: 14px;
  font-size: 12px;
  color: #999999;
  margin-top: 13px;
  width: 270px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
